package com.example.knowledge.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.baselib.base.BaseMVPActivity;
import com.example.baselib.baseurl.GuidUrl;
import com.example.baselib.mvp.IPresenter;
import com.example.knowledge.fragement.CourseCatalogueFragment;
import com.example.knowledge.fragement.CourseintroductionFragment;
import com.example.knowledge.utils.ViewFindUtils;
import com.example.news.R;
import com.flyco.tablayout.SlidingTabLayout;
import com.gyf.immersionbar.ImmersionBar;
import com.kongzue.dialog.interfaces.OnMenuItemClickListener;
import com.kongzue.dialog.util.DialogSettings;
import com.kongzue.dialog.v3.BottomMenu;

import java.util.ArrayList;

/**
 * 课程详情
 */
@Route(path = GuidUrl.CourseDetail_Activity)
public class CourseDetailActivity extends BaseMVPActivity implements View.OnClickListener {
    private Context mContext = this;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "课程介绍", "课程目录"

    };
    private CourseDetailAdapter mAdapter;

    private RelativeLayout rl_pay;

    @Override
    public int getLayoutId() {
        return R.layout.activity_course_detail;
    }

    @Override
    public void initView() {
        //for (String title : mTitles) {
        mFragments.add(new CourseintroductionFragment());
        mFragments.add(new CourseCatalogueFragment());
        //}


        ViewPager viewPager = findViewById(R.id.viewpage);
        mAdapter = new CourseDetailAdapter(getSupportFragmentManager());
        viewPager.setAdapter(mAdapter);
        SlidingTabLayout slidingTabLayout = findViewById(R.id.tablayout_title);
        slidingTabLayout.setViewPager(viewPager);
        rl_pay = findViewById(R.id.rl_pay);
        rl_pay.setOnClickListener(this);
    }

    @Override
    protected IPresenter createPresenter() {
        return null;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(CourseDetailActivity.this)
                .transparentStatusBar()
                .statusBarDarkFont(false)
                .fitsSystemWindows(false)
                .init();
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.rl_pay) {
            DialogSettings.style = DialogSettings.STYLE.STYLE_MIUI;
            BottomMenu.show(CourseDetailActivity.this, new String[]{}, new OnMenuItemClickListener() {
                @Override
                public void onClick(String text, int index) {

                }
            }).setCustomView(R.layout.pay_now_buttom_dialog, new BottomMenu.OnBindView() {
                @Override
                public void onBind(BottomMenu bottomMenu, View v) {
                    //绑定布局事件
                    v.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                        }
                    });
                }
            }).setShowCancelButton(false)

            //.setStyle(dia)
            ;
        }
    }

    private class CourseDetailAdapter extends FragmentPagerAdapter {
        public CourseDetailAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
